package com.mall.tiktokmall.auth.service.imp;

import cn.dev33.satoken.stp.StpUtil;
import com.mall.tiktokmall.auth.domain.dataobject.User;
import com.mall.tiktokmall.auth.domain.dataobject.UserLoginDTO;
import com.mall.tiktokmall.auth.mapper.UserMapper;
import com.mall.tiktokmall.auth.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImp implements UserService {


    @Autowired
    UserMapper userMapper;
    @Override
    public String login(UserLoginDTO userLoginDTO) {

        User user = userMapper.selectUser(userLoginDTO.getId());
        if (user == null) return null;
        Long id = user.getId();
        if (userLoginDTO.getPassword().equals(user.getPassword())) {
            StpUtil.login(id);
            String token = StpUtil.getTokenValue();
            return token;
        }
        return null;
    }
}
